<?php
class ExamesController extends AppController {

	var $name = 'Exames';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->Exame->recursive = 0;
		$this->set('exames', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Exame.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('exame', $this->Exame->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Exame->create();
			if ($this->Exame->save($this->data)) {
				$this->Session->setFlash(__('The Exame has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Exame could not be saved. Please, try again.', true));
			}
		}
		$medicos = $this->Exame->Medico->find('list');
		$funcionarios = $this->Exame->Funcionario->find('list');
		$tiposexames = $this->Exame->Tiposexame->find('list');
		$todosMedicos = $this->Exame->Medico->find('all');
		/*$this->Exame->bindModel{
			array('belongsTo' => array(
					'Pessoa' => array(
						'className' => 'Pessoa',
						//'foreignKey' => 'pessoa_id',))
				)))
		};*/
		$this->set(compact('medicos', 'funcionarios', 'tiposexames')); 
		


	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Exame', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Exame->save($this->data)) {
				$this->Session->setFlash(__('The Exame has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Exame could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Exame->read(null, $id);
		}
		$medicos = $this->Exame->Medico->find('list');
		$funcionarios = $this->Exame->Funcionario->find('list');
		$tiposexames = $this->Exame->Tiposexame->find('list');
		$todosMedicos = $this->Exame->Medico->find('all');
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Exame', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Exame->del($id)) {
			$this->Session->setFlash(__('Exame deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>